package org.shj.book2.chapter12;

import org.shj.book2.chapter12.active.ActiveObject;
import org.shj.book2.chapter12.active.Result;


public class MakerClientThread extends Thread{

	private final ActiveObject activeObj;
	
	private final char fillchar;
	
	public MakerClientThread(String name, ActiveObject activeObj){
		super(name);
		this.activeObj = activeObj;
		this.fillchar = name.charAt(0);
	}
	
	public void run(){
		try{
			for ( int i = 0 ; true ; i++){
				Result result = activeObj.makeString(i, fillchar);
				Thread.sleep(10); //模拟耗时操作
				
				String val = (String) result.getResultValue();//利用Future Pattern，在真正有值返回前，线程一直在等待
				
				System.out.println(Thread.currentThread().getName() + ": value = " + val);
			}
		}catch(InterruptedException e){
			
		}
	}
}
